/* 
 *  Syntelos XB
 *  Copyright (C) 2006 John Pritchard.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307 USA
 */

package syntelos.xb;

/** 
 * <p> Child of {@link Class}. </p>
 * 
 * @author jdp
 */
public class Version 
    extends Base
{
    public final static syntelos.iou.dom.Name NAME = new syntelos.iou.dom.impl.Name(ELEMENT_NODE,"http://www.syntelos.org/xb","xb:version");

    public Version(org.w3c.dom.Document doc, syntelos.iou.dom.Name name){
        super(doc,name);
    }
    public Version(org.w3c.dom.Document doc){
        this(doc,NAME);
    }
    public Version(){
        this(DOC_NIL);
    }

    /**
     * <p> Set default <code>46.0</code> for compilation from
     * XA.</code>
     */
    public final void init(){
        this.setMinor(0);
        this.setMajor(46);
    }
    public final int getMajor(){
        java.lang.Integer major = (java.lang.Integer)this.getDataField("major",IO.Data.INTEGER,this);
        if (null != major)
            return major.intValue();
        else 
            throw new Error.Bug();
    }
    protected final void setMajor(java.lang.Integer major){
        if (null == major)
            throw new Error.Bug();
        else
            this.setDataField("major",major,this);
    }
    public final void setMajor(int major){
        if (45 > major || java.lang.Short.MAX_VALUE <= major)
            throw new Error.Bug(java.lang.String.valueOf(major));
        else
            this.setMajor(new java.lang.Integer(major));
    }

    public final int getMinor(){
        java.lang.Integer minor = (java.lang.Integer)this.getDataField("minor",IO.Data.INTEGER,this);
        if (null != minor)
            return minor.intValue();
        else
            throw new Error.Bug();
    }
    protected final void setMinor(java.lang.Integer minor){
        if (null == minor)
            throw new Error.Bug();
        else
            this.setDataField("minor",minor,this);
    }
    public final void setMinor(int minor){
        this.setMinor(new java.lang.Integer(minor));
    }

    public void readCF(IO.Uri src, CF.Reader reader)
        throws java.io.IOException
    {
        int minor = reader.readUnsignedShort();
        this.setMinor(minor);
        int major = reader.readUnsignedShort();
        this.setMajor(major);
    }
    public void writeCF(IO.Uri dst, CF.Writer writer)
        throws java.io.IOException
    {
        int minor = this.getMinor();
        writer.writeShort(minor);
        int major = this.getMajor();
        writer.writeShort(major);
    }
}
